<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>父子元素间的垂直外边距塌陷</title>
    <style>
      .con {
        float: left;
        width: 33.333333%;
        height: 500px;
        box-sizing: border-box;
        border: 1px solid red;
      }

      .block {
        width: 100%;
        height: 100px;
        background-color: magenta;
      }

      .parent {
        width: 80%;
        height: 100px;
        margin: 0 auto;
        background-color: pink;
      }

      .son {
        width: 50%;
        height: 50px;
        margin: 0 auto;
        background-color: cyan;
      }
    </style>
  </head>

  <body>
    <!-- 相邻垂直外边距都为正值的情况 -->
    <div class="con">
      <div class="block"></div>
      <div class="parent" style="margin-top: 100px">
        <div class="son" style="margin-top: 50px"></div>
      </div>
    </div>

    <!-- 相邻垂直外边距都为一正一负的情况 -->
    <div class="con">
      <div class="block"></div>
      <div class="parent" style="margin-top: 100px">
        <div class="son" style="margin-top: -50px"></div>
      </div>
    </div>

    <!-- 相邻垂直外边距都为负值的情况 -->
    <div class="con">
      <div class="block"></div>
      <div class="parent" style="margin-top: -100px">
        <div class="son" style="margin-top: -50px"></div>
      </div>
    </div>
  </body>
</html>
